package com.freecloud.whispered.system.controller;


import com.freecloud.framework.constant.Constant;
import com.freecloud.framework.constant.Constant.CloudApp;
import com.freecloud.whispered.auth.controller.AbstractController;
import com.freecloud.whispered.system.entity.SysConfigEntity;
import com.freecloud.whispered.system.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: maomao
 * @Date: 2019-08-09 08:32
 */
@Api
@RestController
@RequestMapping("/feign/sys/config")
public class SysConfigFeignController extends AbstractController {
    @Autowired
    private SysConfigService sysConfigService;

    @ApiOperation(value = "获取配置", notes = "获取配置，内部服务调用")
    @PostMapping("/queryObjectByKey")
    @ResponseBody
    @RequiresPermissions("system:feign")
    public SysConfigEntity queryObjectByKey(@RequestParam("key") String key){
        return sysConfigService.queryObjectByKey(key);
    }

    @ApiOperation(value = "根据Key修改配置", notes = "根据Key修改配置，内部服务调用")
    @PostMapping("/updateValueByKey")
    @ResponseBody
    @RequiresPermissions("system:feign")
    public void updateValueByKey(@RequestParam("key")String key, @RequestParam("value") String value){
        sysConfigService.updateValueByKey(key,value);
    }

    @ApiOperation(value = "根据Key获取对应对象", notes = "需要value是json字符串")
    @PostMapping("/getConfigObject")
    @ResponseBody
    @RequiresPermissions("system:feign")
    public <T> T getConfigObject(String key, Class<T> clazz){
        return sysConfigService.getConfigObject(key,clazz);
    }


    @ApiOperation(value = "根据Key获取对应Value值", notes = "根据Key获取对应Value值")
    @PostMapping("/getValue")
    @ResponseBody
    @RequiresPermissions("system:feign")
    public String getValue(String key, String defaultValue){
        return sysConfigService.getValue(key,defaultValue);
    }
}
